#!/bin/bash

rm -fr bin

mkdir -p bin

CFLAGS="-g `odkutils-config --cflags`"

echo "Compiling libfmail"
g++ src/baseserver.cpp -I./include ${CFLAGS} -c -o bin/baseserver.o
g++ src/socket.cpp -I./include ${CFLAGS} -c -o bin/socket.o
g++ src/socketset.cpp -I./include ${CFLAGS} -c -o bin/socketset.o
g++ src/ipcmsg.cpp -I./include ${CFLAGS} -c -o bin/ipcmsg.o

g++ src/socketipc.cpp -I./include ${CFLAGS} -c -o bin/socketipc.o
g++ src/ipc.cpp -I./include ${CFLAGS} -c -o bin/ipc.o

g++ bin/baseserver.o bin/socket.o bin/socketipc.o bin/ipc.o bin/ipcmsg.o `odkutils-config --libs` -lstdc++ -shared -o bin/libfmail.so

#echo "Compiling Testcases"
#g++ testcase/ipctest.cpp -lfmail -g -I./include -L./bin -o bin/ipctest
#g++ testcase/ipccommand.cpp -lfmail -g -I./include -L./bin -o bin/ipccommand

echo "Compiling Protocols"
g++ backends/protocol/pop3.cpp -lstdc++ `odkutils-config --libs --cflags` -I./include -L./bin -lfmail -shared ${CFLAGS} -o bin/libfmail-pop3.so
g++ backends/protocol/smtp.cpp -lstdc++ -I./include -L./bin -lfmail -shared ${CFLAGS} -o bin/libfmail-smtp.so
g++ backends/auth/fsauth.cpp -lstdc++ -I./include -L./bin -lfmail `odkutils-config --libs` ${CFLAGS} -o bin/fmail-fsauth
g++ backends/mailbox/fsmailbox.cpp -lstdc++ -I./include -L./bin -lfmail `odkutils-config --libs` ${CFLAGS} -o bin/fmail-fsmailbox

echo "Compiling FancyMail Server"
g++ src/fmail.cpp -I./include -L./bin -lfmail -lstdc++ `odkutils-config --libs` ${CFLAGS} -o bin/fmail
g++ backends/protocol/pop3.cpp -I./include -L./bin -lfmail -lstdc++ `odkutils-config --libs` ${CFLAGS} -DSTANDALONE -o bin/fmail-pop3
g++ backends/protocol/smtp.cpp -I./include -L./bin -lfmail -lstdc++ `odkutils-config --libs` ${CFLAGS} -DSTANDALONE -o bin/fmail-smtp
